<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button @click="searchQuery" type="primary" icon="search">查询</a-button>
      <!-- <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown> -->
    </div>

    <!-- table区域-begin -->
    <div>
      <!-- <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div> -->

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">
        <!-- :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"   选择框 -->

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <template slot="applyStatus" slot-scope="text,record">
          <span v-if="record.applyStatus == '1'" >进行中</span>
          <span v-if="record.applyStatus == '2'" >完成</span>
          <span v-if="record.applyStatus == '3'" >撤销</span>
        </template>

        <template slot="result" slot-scope="text,record">
          <span v-if="record.result == '0'" >拒绝</span>
          <span v-if="record.result == '1'" >同意</span>
        </template>

        <span slot="action" slot-scope="text, record">
          <!-- <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" /> -->
          <a @click="handleDetail(record)">详情</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="getPreviewImage(record)">流程图</a>
              </a-menu-item>
              <a-menu-item>
                <a @click="getApprovalList(record)">审批记录</a>
              </a-menu-item>
              <!-- <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item> -->
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <apply-leave-modal ref="modalForm" @ok="modalFormOk"></apply-leave-modal>
    <image-modal ref="imageModal" />
    <approva-str ref="approvaStr"></approva-str>
  </a-card>
</template>

<script>
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ApplyLeaveModal from './modules/ApplyLeaveModal'
  import ImageModal from './ImageModal'
  import ApprovaStr from './ApprovaStr'

  export default {
    name: 'ApplyLeaveList',
    mixins: [JeecgListMixin, mixinDevice],
    components: {
      ApplyLeaveModal, ImageModal, ApprovaStr
    },
    data () {
      return {
        description: 'apply_leave管理页面',

        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1
            }
          },
          {
            title: '部门名称',
            align: 'center',
            dataIndex: 'deptName'
          },
          {
            title: '流程实例',
            align: 'center',
            dataIndex: 'processInstanceId'
          },
          {
            title: '流程KEY',
            align: 'center',
            dataIndex: 'processKey'
          },
          {
            title: '表单',
            align: 'center',
            dataIndex: 'formKey'
          },
          {
            title: '发起人名称',
            align: 'center',
            dataIndex: 'userName'
          },

          {
            title: '天数',
            align: 'center',
            dataIndex: 'total'
          },
          {
            title: '备注',
            align: 'center',
            dataIndex: 'remarks'
          },
          {
            title: '审批状态 ', // 1进行中，2完成，3已撤销
            align: 'center',
            dataIndex: 'applyStatus',
            scopedSlots: { customRender: 'applyStatus' }
          },
          {
            title: '审批结果', // 0拒绝 1同意
            align: 'center',
            dataIndex: 'result',
            scopedSlots: { customRender: 'result' }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed: 'right',
            width: 147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: '/apply/applyLeave/list',
          delete: '/apply/applyLeave/delete',
          deleteBatch: '/apply/applyLeave/deleteBatch',
          exportXlsUrl: '/apply/applyLeave/exportXls',
          importExcelUrl: 'apply/applyLeave/importExcel'

        },
        dictOptions: {},
        superFieldList: []
      }
    },
    created() {
      this.getSuperFieldList()
    },
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
      }
    },
    methods: {
      getPreviewImage(item) {
          this.$refs.imageModal.openModel(item)
      },
      getApprovalList(item) {
          this.$refs.approvaStr.openModel(item)
      },
      initDictConfig() {
      },
      getSuperFieldList() {
        let fieldList = []
        fieldList.push({ type: 'string', value: 'deptId', text: '部门id' })
        fieldList.push({ type: 'string', value: 'deptName', text: '部门名称' })
        fieldList.push({ type: 'string', value: 'processinstanceid', text: '流程实例' })
        fieldList.push({ type: 'string', value: 'processinstancename', text: '流程实例名称' })
        fieldList.push({ type: 'string', value: 'processkey', text: '流程key' })
        fieldList.push({ type: 'string', value: 'formkey', text: '表单' })
        fieldList.push({ type: 'string', value: 'userid', text: '申请人id' })
        fieldList.push({ type: 'string', value: 'username', text: '申请人名称' })
        fieldList.push({ type: 'string', value: 'delFlag', text: '是否删除' })
        fieldList.push({ type: 'int', value: 'total', text: '天数' })
        fieldList.push({ type: 'string', value: 'opinionstr', text: '审批记录' })
        fieldList.push({ type: 'string', value: 'remarks', text: '备注' })
        fieldList.push({ type: 'string', value: 'applystatus', text: '审批状态 1进行中，2完成，3已撤销' })
        fieldList.push({ type: 'string', value: 'result', text: '最终审批结果 0拒绝 1同意, 2驳回' })
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
